home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Framework / Includes / UMacAppUtilities.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  13.4 KB  |  469 lines  |  [TEXT/MPS ]

  1. // UMacAppUtilities.h
  2. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #ifndef __UMACAPPUTILITIES__
  5. #define __UMACAPPUTILITIES__
  6.  
  7. // MacApp
  8.  
  9. #ifndef __MACAPPTYPES__
  10. #include "MacAppTypes.h"
  11. #endif
  12.  
  13. #ifndef __PASCALSTRING__
  14. #include "PascalString.h"
  15. #endif
  16.  
  17. #ifndef __TOOLBOX__
  18. #include "Toolbox.h"
  19. #endif
  20.  
  21. #ifndef __UCOREUTILITIES__
  22. #include "UCoreUtilities.h"
  23. #endif
  24.  
  25. #ifndef __UGEOMETRY__
  26. #include "UGeometry.h"
  27. #endif
  28.  
  29. #ifndef __UITERATOR__
  30. #include "UIterator.h"
  31. #endif
  32.  
  33. // Toolbox
  34.  
  35. #ifndef __APPLEEVENTS__
  36. #include <AppleEvents.h>
  37. #endif
  38.  
  39. #ifndef __EDITIONS__
  40. #include <Editions.h>
  41. #endif
  42.  
  43. #ifndef __LOWMEM__
  44. #include <LowMem.h>
  45. #endif
  46.  
  47. #ifndef __QUICKDRAW__
  48. #include <Quickdraw.h>
  49. #endif
  50.  
  51. #ifndef __RESOURCES__
  52. #include <Resources.h>
  53. #endif
  54.  
  55. //----------------------------------------------------------------------------------------
  56. // Forward declarations
  57. //----------------------------------------------------------------------------------------
  58. class TStream;
  59. class TView;
  60.  
  61. //----------------------------------------------------------------------------------------
  62. // Global constants declarations. Build options.
  63. //----------------------------------------------------------------------------------------
  64.  
  65. // constants passed in as flags to MATextBox()
  66. enum { kDontPreferOutline, kPreferOutline };
  67.  
  68. //----------------------------------------------------------------------------------------
  69. // Some useful struct(s)
  70. //----------------------------------------------------------------------------------------
  71.  
  72. #if PRAGMA_ALIGN_SUPPORTED
  73. #pragma options align=mac68k
  74. #endif
  75.  
  76. struct MATextStyle
  77. {
  78.     Style tsFace;                    // character Style
  79.     char filler;                    // tsFace is unpacked byte
  80.     short tsSize;                    // size in points
  81.     CRGBColor tsColor;                // absolute (RGB) color
  82.     CStr255 tsFont;                    // font (family) number
  83. };
  84.  
  85. #if PRAGMA_ALIGN_SUPPORTED
  86. #pragma options align=reset
  87. #endif
  88.  
  89. typedef MATextStyle *MATextStylePtr, **MATextStyleHandle;
  90.  
  91.  
  92. //----------------------------------------------------------------------------------------
  93. // Global variable declarations.
  94. //----------------------------------------------------------------------------------------
  95.  
  96. #if qDebugMsg
  97. extern const CStr15 gBoolString[2];
  98. #endif
  99. extern Boolean gUDialogInitialized;
  100. extern Boolean gUGridViewInitialized;
  101. extern Boolean gUPrintingInitialized;
  102. extern Boolean gUTEViewInitialized;
  103. extern TEHandle gMATextBoxTE;
  104. extern WordBreakUPP gTEDefaultWordBreak;
  105. extern const VHSelect gOrthogonal[2];
  106. extern const CRect gZeroRect;
  107. extern const CPoint gZeroPt;
  108. extern const VPoint gZeroVPt;
  109. extern const VRect gZeroVRect;
  110. extern const CPoint kBestSystemLocation;    // use when system calls take -1,-1 for best window locations
  111. extern const CStr2 gEmptyString;
  112. extern const CRGBColor gRGBBlack;
  113. extern const CRGBColor gRGBWhite;
  114. extern const CRGBColor gRGBRed;
  115. extern const CRGBColor gRGBGreen;
  116. extern const CRGBColor gRGBBlue;
  117.  
  118. //------------------------------------------------------------------------------------
  119. // CWhileOutlinePreferred: A simple class for setting/restoring outline preferred.
  120. //------------------------------------------------------------------------------------
  121.  
  122. class CWhileOutlinePreferred
  123. {
  124.     Boolean fPreferOutline;
  125.     Boolean fOutlinePreferredChanged;
  126.  
  127. public:
  128.     // Constructor/destructor
  129.     CWhileOutlinePreferred(Boolean preferOutline);
  130.     ~CWhileOutlinePreferred();
  131. };
  132.  
  133. //----------------------------------------------------------------------------------------
  134. // CStringListRsrc: A simple class for managing and accessing strings in STR# resources.
  135. //
  136. // Limitations: this class has no notion of which resource file to be used for accessing
  137. // the strings from the CString list resource.  This could be added as an enhancement.
  138. //----------------------------------------------------------------------------------------
  139.  
  140. class CStringListRsrc
  141. {
  142. public:
  143.     //----------------------------------------------------------------------------------------
  144.     // class-scoped constants
  145.     //----------------------------------------------------------------------------------------
  146.     enum { kDontAddString, kAddString };
  147.  
  148.     //----------------------------------------------------------------------------------------
  149.     // constructors
  150.     //----------------------------------------------------------------------------------------
  151.     inline CStringListRsrc(short strListID, const CStr255& strListRsrcName) :
  152.             fStrListID(strListID),
  153.             fStrListRsrcName(strListRsrcName)
  154.             {}
  155.         // constructor
  156.  
  157.     inline CStringListRsrc(short strListID) :
  158.             fStrListID(strListID)
  159.             {  }
  160.         // constructor
  161.  
  162.     //----------------------------------------------------------------------------------------
  163.     // accessors
  164.     //----------------------------------------------------------------------------------------
  165.     short AppendString(const CStr255& theString);
  166.         // append theString to the STR# resource whose id is fStrListID and return its index
  167.     
  168.     void ClearAll();
  169.         // clears all strings in the STR# resource
  170.  
  171.     short CountStrings() const;
  172.         // returns the number of strings in the STR# resource whose id is fStrListID
  173.  
  174.     short FindString(const CStr255& theString, Boolean addString = kDontAddString);
  175.         // find theString in the STR# resource whose id is fStrListID and return its index
  176.         // if theString is not found in the STR# resource, add it if addString is kAddString
  177.     
  178.     void GetListName(CStr255& itsName);
  179.         //    Returns the name of the STR# list either from its field or if that is empty
  180.         //    from the actual resource
  181.  
  182.     void GetString(short index, CStr255& theString) const;
  183.         // return in theString the "index" CString in the STR# resource whose id is fStrListID
  184.  
  185.     void RemoveAt(short index);
  186.         // removes the CString at the specified index.
  187.     
  188.     void ReplaceAt(const CStr255& theString, short index);
  189.         // replace the CString at "index" with "theString"
  190.  
  191.     //----------------------------------------------------------------------------------------
  192.     // data members
  193.     //----------------------------------------------------------------------------------------
  194. protected:
  195.     CStr255        fStrListRsrcName;            // The name of the STR# rsrc, this is
  196.                                             // only used when adding the STR# rsrc.
  197.     ResNumber    fStrListID;                    // The ID of the STR# rsrc.
  198. };
  199.  
  200.  
  201. //----------------------------------------------------------------------------------------
  202. // CWMgrIterator: A simple iterator for window lists.
  203. //----------------------------------------------------------------------------------------
  204.  
  205. class CWMgrIterator
  206. {
  207. private:
  208.     WindowRef fCurrentWindow;
  209.     
  210. protected:
  211.     Boolean fIterateForward;
  212.  
  213. public:
  214.     CWMgrIterator(Boolean itsForward = TRUE);
  215.  
  216.     inline Boolean More()                    // override
  217.     { return (fCurrentWindow != NULL); }
  218.         // Returns true if there are more elements to iterate over
  219.  
  220.     void Reset();                    // override
  221.         // Resets the iterator to begin again
  222.  
  223.     inline WindowRef CurrentWMgrWindow()
  224.     { return fCurrentWindow; }                        // Always return the current window
  225.  
  226.         // returns the current window
  227.  
  228.     WindowRef FirstWMgrWindow();
  229.         // Resets the iterator to begin again and returns the first window in the window list
  230.  
  231.     WindowRef NextWMgrWindow();
  232.         // increments and then returns the window in the window list
  233.  
  234. protected:
  235.     void Advance();                    // override
  236.         // Advances the iteration
  237.  
  238.     WindowRef NextWindow(WindowRef aWindow);
  239.         // returns the next window in the window list, excluding gWorkPort
  240.         
  241.     WindowRef PreviousWindow(WindowRef aWindow);
  242.         // returns the previous window in the window list, excluding gWorkPort
  243.  
  244.     WindowRef FirstWindow();
  245.         // returns the first window in the window list, excluding gWorkPort
  246.         
  247.     WindowRef LastWindow();
  248.         // returns the last window in the window list, excluding gWorkPort
  249.  
  250. };
  251.  
  252.  
  253. //----------------------------------------------------------------------------------------
  254. // Global function declarations that needs to always be compiled for 68000.
  255. //----------------------------------------------------------------------------------------
  256.  
  257. void CenterRectOnScreen(CRect& aRect,
  258.                         Boolean horizontally,
  259.                         Boolean vertically,
  260.                         Boolean forDialog);
  261.  
  262. void ConcatNumber(const CStr255& aString,
  263.                   long aNumber,
  264.                   CStr255& theResult);
  265.  
  266. void PullApplicationToFront();
  267.  
  268. inline void SetRGBColor(CRGBColor& RGB,
  269.                  short aRed,
  270.                  short aGreen,
  271.                  short aBlue)
  272. { RGB.red = aRed; RGB.green = aGreen; RGB.blue = aBlue; }
  273.  
  274. OSErr MAInteractWithUser(long timeOutInTicks, NMRecPtr nmReqPtr, AEIdleUPP idleProc);
  275.  
  276. OSErr MAInteractWithUser();
  277.  
  278. OSErr MAInteractWithUserNoIdleProc();
  279.  
  280. //----------------------------------------------------------------------------------------
  281. // Global function declarations
  282. //----------------------------------------------------------------------------------------
  283.  
  284. #if qNeedsSystem7_5
  285. inline short MACharacterByteType(Ptr textBuf, short textOffset, ScriptCode script)
  286. { return CharacterByteType(textBuf, textOffset, script); }
  287. #else
  288. short MACharacterByteType(Ptr textBuf, short textOffset, ScriptCode script);
  289. #endif
  290.  
  291. #if qNeedsSystem7_5
  292. inline short MACharacterType(Ptr textBuf, short textOffset, ScriptCode script)
  293. { return CharacterType(textBuf, textOffset, script); }
  294. #else
  295. short MACharacterType(Ptr textBuf, short textOffset, ScriptCode script);
  296. #endif
  297.  
  298. Boolean CompareMultiByteChars(const CStr31& first,
  299.                               const CStr31& second,
  300.                               Boolean caseSens);
  301.     // Special case single byte characters and allow case insensitive comparisons
  302.  
  303. inline short CompareStrings(const CStr255& first, const CStr255& second)
  304. { return ::CompareString(first, second, NULL); }
  305.  
  306. inline void CopyStr255(const CStr255& fmStr, Ptr toAddr)
  307. { fmStr.CopyTo((unsigned char*)toAddr); }
  308.  
  309. WindowRef FindWindowBefore(WindowRef theWindow);
  310.  
  311. void DefaultSize(short& theSize);
  312.  
  313. PicHandle DisposeIfPicHandle(PicHandle aPicHandle);
  314.  
  315. RgnHandle DisposeIfRgnHandle(RgnHandle aRgnHandle);
  316.  
  317. SectionHandle DisposeIfSectionHandle(SectionHandle aSectionHandle);
  318.  
  319. short GetActualJustification(short justification);
  320.  
  321. void GetDeskTopRegion(RgnHandle deskTopRgn);
  322.  
  323. void ShowGlobalRegion(RgnHandle globalRegion);
  324.  
  325. void ShowViewRegion(TView *theView, RgnHandle viewRegion);
  326.  
  327. short GetFontNum(const CStr255& fontName);
  328.  
  329. CRGBColor GetIfColor();
  330. inline void GetIfColor(CRGBColor& aColor)
  331. { aColor = GetIfColor(); }
  332.  
  333. CRGBColor GetIfBkColor();
  334. inline void GetIfBkColor(CRGBColor& aColor)
  335. { aColor = GetIfBkColor(); }
  336.  
  337. void GetPortTextStyle(TextStyle& theTextStyle);
  338.  
  339. void MAGetTextStyle(ResNumber rsrcID, TextStyle& theTextStyle);
  340. // Given the rsrcID of a 'TxSt' resource, this function creates and
  341. // returns in theTextStyle the corresponding TextStyle record.
  342.  
  343. void GetPortFontInfo(short fontNum, CStr255& fontName, short& fontSize);
  344.  
  345. long GetRandom(long rangeStart, long rangeEnd);
  346.  
  347. Boolean IsColorPort(GrafPtr port);
  348.  
  349. inline short GetWindowVariant(WindowRef theWindow)
  350. { return GetWVariant(theWindow); }
  351. // For MacApp 3.0 app's, _GetWVariant is *always* available.
  352.  
  353. inline short LengthRect(const CRect& r, VHSelect vhs)
  354. { return r.GetLength(vhs); }
  355.  
  356. VHSelect LongerSide(CRect& r);
  357.  
  358. VHSelect LongerVSide(VRect& r);
  359.  
  360. void LIntToHex(long decNumber, CStr31& hexNumber, short noOfDigits);
  361.  
  362. short MAGetFontInfo(FontInfo& theFontInfo);
  363.  
  364. void MATextBox(Ptr text,
  365.                long itsLength,
  366.                const CRect& box,
  367.                short itsJust,
  368.                Boolean autoWrap,
  369.                ProcPtr wordBreak,
  370.                Boolean eraseFirst,
  371.                Boolean spaceForCaret,
  372.                Boolean preferOutline = kDontPreferOutline);
  373.  
  374. void MADrawString(const CStr255& s,
  375.                   const CRect& box,
  376.                   short justification,
  377.                   Boolean preferOutline = kDontPreferOutline);
  378.  
  379. void NumberToHex(long theNumber,
  380.                  CStr255& hexString,
  381.                  short hexDigits);
  382.  
  383. Boolean IsThisKeyDown(const short theKey);
  384. // Returns TRUE if the specified key is currently depressed. (Pushed down, not unhappy!)
  385.  
  386. Boolean IsCapsLockKeyDown();
  387.  
  388. Boolean IsCommandKeyDown();
  389.  
  390. Boolean IsControlKeyDown();
  391.  
  392. Boolean IsOptionKeyDown();
  393.  
  394. Boolean IsShiftKeyDown();
  395.  
  396. long PinOnRect(const CRect& theRect, CPoint thePt);
  397.  
  398. void PinOnVRect(const VRect& theRect, const VPoint& thePt, VPoint& thePin);
  399.  
  400. void PointerToHex(long theNumber, CStr31& hexString, short hexDigits);
  401.  
  402. inline Boolean RectsNest(const CRect& outer, const CRect& inner)
  403. { return outer.Contains(inner); }
  404.  
  405. inline Boolean VRectsNest(const VRect& outer, const VRect& inner)
  406. { return outer.Contains(inner); }
  407.  
  408. long RoundUp(long aNumber, short aModulus);
  409.  
  410. short SetKeyScript(short newKeyScript);
  411.  
  412. void SetIfColor(const CRGBColor& aColor);
  413.  
  414. void SetIfBkColor(const CRGBColor& aColor);
  415.  
  416. void SetPortTextStyle(const TextStyle& theTextStyle);
  417.  
  418. void SetTextStyle(TextStyle& theTextStyle,
  419.                   short theFont,
  420.                   /* Style */
  421.                   short theStyle,
  422.                   short theSize,
  423.                   const CRGBColor& theColor);
  424.  
  425. void UseSelectionColor();
  426.  
  427. void UseROMMap(Boolean resLoad);
  428.  
  429. long NumBlocks(long numBytes, long blkSize);
  430.  
  431. #if qDebug
  432. Boolean CanReadLn();
  433. #else
  434. inline Boolean CanReadLn()
  435. { return FALSE; }
  436. #endif
  437.  
  438. #if qDebug
  439. Boolean CanWriteLn();
  440. #else
  441. inline Boolean CanWriteLn()
  442. { return FALSE; }
  443. #endif
  444.  
  445. inline void CopyPat(const Pattern& pat, Pattern& toPat)
  446. { toPat = pat; } // Patterns are structures now
  447.  
  448. void XorPat(const Pattern& patA, const Pattern& patB, Pattern& toPat);
  449.  
  450. void RotatePat(Pattern& aPattern);
  451.  
  452. Handle StreamToHandle(TStream* theStream);
  453.  
  454. //----------------------------------------------------------------------------------------
  455. // System configuration.
  456. //----------------------------------------------------------------------------------------
  457.  
  458. #if qOldConfigurationFlags
  459.  
  460. // The Configuration structure and gConfiguration are obsolete. 
  461. // Use the configuration functions in UMacAppUtilities instead. 
  462. // For example, instead of gConfiguration.hasSpeechManager, 
  463. // use HasSpeechManager(). 
  464.  
  465. extern Configuration gConfiguration;
  466. #endif
  467.  
  468. #endif // __UMACAPPUTILITIES__
  469.